package com.sto.stoapp.activity.scanner;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.activity.scanner.upload.UploadDataActivity;
import com.sto.stoapp.adapter.InquiryMenuAdapter;
import com.sto.stoapp.dataprocess.ProcessTableData;
import com.sto.stoapp.dataprocess.ProcessUploadData;
import com.sto.stoapp.entity.InquiryEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.util.UnifiedStaticType;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

public class StoUnUploadDataActivity extends StoHomeActivity{
	private ListView datalist = null; // 定义ListView组件
	private List<InquiryEntity> list = new ArrayList<InquiryEntity>(); // 定义显示的内容包装
	private InquiryEntity inquiryEntity;
	private ProcessTableData tableData;

	//Add by wj
	private Button confirmBtn;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.sto_inquirymenu_list);
		Bundle extras = getIntent().getExtras();
		this.setTitleBottom(R.string.un_upload,
				extras.getString("busiType"));
		
		tableData = new ProcessTableData();
		initWidget();
		//Add by wj
		confirmBtn= (Button) findViewById(R.id.comfirm);
		confirmBtn.setText("全部上传");
		confirmBtn.setTextSize(16);
		confirmBtn.setTextColor(getResources().getColor(R.color.white));
		confirmBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(UnifiedStaticType.UP_ACTION);
				intent.putIntegerArrayListExtra(UnifiedStaticType.UPLOAD_TYPE,
						new ProcessUploadData().sendAllData());
				sendBroadcast(intent);
			}
		});
		//End by wj
	}

	private void initWidget() {
		this.datalist = (ListView) super.findViewById(R.id.dest_list); // 取得组件
		datalist.setOnItemClickListener(new StoOnItemClickListener(this) {
			@Override
			public void KcOnItemClickListener(AdapterView<?> parent, View view,
					int position, long id) {
				String itemText = list.get(position).getMenuName();
				Intent intent = new Intent(StoUnUploadDataActivity.this,
						UploadDataActivity.class);
				//查询数据项名称
				intent.putExtra("inquiryNameItem", tableData.getProcessUploadData(position,0));
				//查询对应表名的序号
				intent.putExtra("inquiryTableItem", tableData.getProcessUploadData(position,1));
				intent.putExtra("inquiryItemText", itemText);
				startActivity(intent);
			}
		});

		displayListView();
	}

	private void displayListView() {
		int maxItem = tableData.getUploadMaxItem();
		
		for (int x = 0; x < maxItem; x++) {
			inquiryEntity = new InquiryEntity();
			inquiryEntity
					.setMenuName(getString(tableData.getProcessUploadData(x,0)));
			inquiryEntity.setImageId(R.drawable.next);
			this.list.add(inquiryEntity); // 保存了所有的数据行

		}
		InquiryMenuAdapter menuAdapter = new InquiryMenuAdapter(this, list);
		datalist.setAdapter(menuAdapter);
	}

}
